package org.sidora.strata.site;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.windows.TopComponent;
import org.sidora.core.Action;
import org.sidora.strata.SidoraTools;


/**
 * Action which shows ActionForm component.
 * @author Enric Tartera, Juan Manuel Gimeno, Roger Masgoret
 * @version 1.0
 */
public class ActionFormAction extends AbstractAction {
    
    public ActionFormAction() {
        super(NbBundle.getMessage(ActionFormAction.class, "CTL_ActionFormAction"));
//        putValue(SMALL_ICON, new ImageIcon(Utilities.loadImage(ActionFormTopComponent.ICON_PATH, true)));
    }
    
    public void actionPerformed(ActionEvent evt) {
        TopComponent win = ActionFormTopComponent.findInstance();
        win.open();
        win.requestActive();
    }
    
     public void actionPerformed(Action action) {
        ActionFormTopComponent aftc;
        aftc = (ActionFormTopComponent)ActionFormTopComponent.findInstance();
        aftc.saveAllData();
        aftc.setAction(action);
        aftc.fillActionFields();
        aftc.open();
        aftc.requestActive();
    }
    
    public void clearFields(){
        ActionFormTopComponent aftc;
        aftc = (ActionFormTopComponent)ActionFormTopComponent.findInstance();
        aftc.emptyActionFields();
    }
    
    public void close() {
        ActionFormTopComponent win = ActionFormTopComponent.findInstance();
        win.saveAllData();
        win.close();
    }
    
}
